﻿using Core.Infrastructures.Cores.Injections.Dependencies;
using Core.Infrastructures.Cores.Models;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;

namespace Core.Services
{
    public partial interface IBaseService<TEntity, TDto> : IServiceDependency where TEntity : class, IEntity, new() where TDto : class, IDto , new()
    {
        //定义返回类型
        HandleResult Result(string output = "success", object extras = default);

        //get type by id
        TDto GetById<TKey>(TKey id);

        /// <summary>
        /// insert 
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        (int, HandleResult) Insert(TDto dto);

        /// <summary>
        /// T, TMap 类型
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TMap"></typeparam>
        /// <param name="dto"></param>
        /// <returns></returns>
        (int, HandleResult) Insert<T, TMap>(TMap dto) where T : class, new() where TMap : class, new();

        /// <summary>
        /// update by dto
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        (int, HandleResult) Update(TDto dto);

        /// <summary>
        /// update by T,TMap
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TMap"></typeparam>
        /// <param name="dto"></param>
        /// <returns></returns>
        (int, HandleResult) Update<T, TMap>(TMap dto) where T : class, new() where TMap : class, new();

        /// <summary>
        /// update columns
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="columns"></param>
        /// <returns></returns>
        (int, HandleResult) UpdateColumns(TDto dto, Expression<Func<TEntity, object>> columns);

        /// <summary>
        /// T,Map
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TMap"></typeparam>
        /// <param name="dto"></param>
        /// <param name="columns"></param>
        /// <returns></returns>
        (int, HandleResult) UpdateColumns<T, TMap>(TMap dto, Expression<Func<T, object>> columns) where T : class, new() where TMap : class, new();

        /// <summary>
        /// delete
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="id"></param>
        /// <returns></returns>
        (int, HandleResult) Delete<TKey>(TKey id);

        /// <summary>
        /// 查找是否存在
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        bool Any(Expression<Func<TEntity, bool>> expression);

        /// <summary>
        /// Expression GetList
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="orderBy"></param>
        /// <returns></returns>
        IEnumerable<TDto> GetList(Expression<Func<TEntity, bool>> expression, string orderBy = null);

        /// <summary>
        /// string expression GetList
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="orderBy"></param>
        /// <returns></returns>
        IEnumerable<TDto> GetList(string expression, string orderBy = null);
        /// <summary>
        /// list by page with Expression
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="orderBy"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="records"></param>
        /// <param name="totalPage"></param>
        /// <returns></returns>
        IEnumerable<TDto> GetListByPage(Expression<Func<TEntity, bool>> expression, string orderBy, int pageIndex, int pageSize, ref int records, ref int totalPage);

        /// <summary>
        /// list by page with string Expression
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="orderBy"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="records"></param>
        /// <param name="totalPage"></param>
        /// <returns></returns>
        IEnumerable<TDto> GetListByPage(string expression, string orderBy, int pageIndex, int pageSize, ref int records, ref int totalPage);

    }
}
